<template>
	<view class="zai-box">
		<image src="../../static/zaizai-login/login.jpg" mode='aspectFit' class="zai-logo"></image>
		<!-- <view class="zai-title">景小点</view> -->
		<view class="zai-form">
			<input class="zai-input" v-model="form.mobile" placeholder="请输入用户名" />
			<input class="zai-input" v-model="form.password" password placeholder="请输入密码" />
			<!-- <view class="zai-label">忘记密码？</view> -->
			<button class="zai-btn" @click="login">立即登录</button>
			<navigator url="/pages/login/register" hover-class="none" class="zai-label">还没有账号？点此注册.</navigator>
		</view>
		<u-notify ref="uNotify"></u-notify>
	</view>

</template>

<script>
	import {
		ResultEnum
	} from '@/enums/httpEnum.js'
	import {
		nextTick
	} from "vue"
	export default {
		data() {
			return {
				form: {
					mobile: '',
					password: '',
					identity: 'USER'
				}
			}
		},
		methods: {
			login() {
				this.$api({
					url: '/auth/login',
					method: 'post',
					data: this.form
				}).then(res => {
					const {
						code,
						data,
						message
					} = res
					if (code == ResultEnum.SUCCESS) {
						uni.setStorage({
							key: 'Authorization',
							data: data
						});
						this.getUserInfo()

						this.$refs.uNotify.primary(message)

					}

				})
			},
			getUserInfo() {
				this.$api({
					url: '/auth/getUserInfo',
					method: 'get',
				}).then(res => {
					const {
						data
					} = res
					uni.setStorage({
						key: 'userInfo',
						data: data
					});
					setTimeout(() => {
						uni.switchTab({
							url: '/pages/index/index'
						})
					}, 1000)
				})
			}
		}
	}
</script>

<style>
	.zai-box {
		padding: 0 100upx;
		position: relative;
	}

	.zai-logo {
		width: 100%;
		width: 100%;
		height: 510upx;
	}

	.zai-title {
		position: absolute;
		top: 0;
		line-height: 360upx;
		font-size: 68upx;
		color: #fff;
		text-align: center;
		width: 100%;
		margin-left: -100upx;
	}

	.zai-form {
		margin-top: 200upx;
	}

	.zai-input {
		background: #e2f5fc;
		margin-top: 30upx;
		border-radius: 100upx;
		padding: 20upx 40upx;
		font-size: 36upx;
	}

	.input-placeholder,
	.zai-input {
		color: #94afce;
	}

	.zai-label {
		padding: 60upx 0;
		text-align: center;
		font-size: 30upx;
		color: #a7b6d0;
	}

	.zai-btn {
		margin: 50rpx 0;
		background: #ff65a3;
		color: #fff;
		border: 0;
		border-radius: 100upx;
		font-size: 36upx;
	}

	.zai-btn:after {
		border: 0;
	}

	/*按钮点击效果*/
	.zai-btn.button-hover {
		transform: translate(1upx, 1upx);
	}
</style>